package alingrad.engine.graphics;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;

import alingrad.engine.collisions.CollisionMaskData;
import alingrad.engine.graphics.primitives.RenderableSquare;


public abstract class RenderablePrimitive extends Renderable {
	protected float[] mVertices;
	protected short[] mIndices;

	protected FloatBuffer mVertexBuffer;
	protected ShortBuffer mIndexBuffer;

	protected boolean mIgnoreTransformations;

	protected float mX;
	protected float mY;

	public RenderablePrimitive(boolean ignore) {
		mIgnoreTransformations = ignore;
	}

	protected void createBuffers() {
		ByteBuffer vbb = ByteBuffer.allocateDirect(mVertices.length * 4);
		vbb.order(ByteOrder.nativeOrder());
		mVertexBuffer = vbb.asFloatBuffer();
		mVertexBuffer.put(mVertices);
		mVertexBuffer.position(0);
		ByteBuffer ibb = ByteBuffer.allocateDirect(mIndices.length * 2);
		ibb.order(ByteOrder.nativeOrder());
		mIndexBuffer = ibb.asShortBuffer();
		mIndexBuffer.put(mIndices);
		mIndexBuffer.position(0);
	}

	public abstract CollisionMaskData getData();

	public static void sLoad() {
		RenderableSquare.sLoad();
	}
}
